package finassist.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.exception.SQLGrammarException;

import com.opensymphony.xwork2.ActionContext;

import finassist.model.Entiti;
import finassist.model.Ledger;
import finassist.model.LedgerSubType;
import finassist.model.LedgerType;
import finassist.model.Test;
import finassist.model.User;
import finassist.DAO.EntityProcessManagerDAO;
import finassist.DAO.LoginUserManagerDAO;
/**
 * AJ Projects
 * LoginUserManager.java
 * Purpose: Login User Database.
 *
 * @author Karthick Natarajan
 * @version 1.0 9/10/13
 */

public class EntityProcessManager {

	public void createEntity(Entiti entiti) {
	EntityProcessManagerDAO logObj = new EntityProcessManagerDAO();
	Test test = new Test();
	
	test.setName("kart");
	test.setPass("past");
		try {
			 logObj.add(entiti);
			// logObj.addTest(test);
		}
		catch (SQLGrammarException e) {
		    e.printStackTrace();
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public List<Ledger> listLedger() {
		
		
		EntityProcessManagerDAO logObj = new EntityProcessManagerDAO();
			List<Ledger> ledgers = null;
			try {
				
				ledgers = logObj.getLedgerDetails();	
				
			} catch (Exception e) {
				e.printStackTrace();
			}
			return ledgers;
		}
	
	public Map<String, List<String>> listLedgerType() {
		
		
		EntityProcessManagerDAO logObj = new EntityProcessManagerDAO();
			List<LedgerType> ledgerTypes = null;
			List<LedgerSubType> ledgerSubTypes = null;
			List<String> subTypes = new ArrayList<String>();
			
			Map<String, List<String>> typeMap = new HashMap<String, List<String>>();
			try {
				
				ledgerTypes = logObj.getLedgerTypeDetails();	
				ledgerSubTypes = logObj.getLedgerSubTypeDetails();	
				
				for (int i = 0; i < ledgerTypes.size(); i++) {
					for (int j = 0; j < ledgerSubTypes.size(); j++) {
						if(ledgerSubTypes.get(j).getLedgerTypeId().equals(ledgerTypes.get(i).getId()))
							subTypes.add(ledgerSubTypes.get(j).getLedgerSubTypeName());
				}
					
					typeMap.put(ledgerTypes.get(i).getLedgerTypeName(),subTypes);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			return typeMap;
		}
}
